﻿@using AdverseEventReportSystem.BLL.SchedulingSystem
@using AdverseEventReportSystem.BLL
@{
    Layout = null;
    SchedulingCategory schedulingCategory = (SchedulingCategory)@Model;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <meta http-equiv="Cache" content="no-cache" />
    <title>班别维护详情</title>
    <link href="~/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
    <link href="~/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
    <link href="~/lib/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
    <link href="~/Content/css/common.css" rel="stylesheet" type="text/css" />
    <script src="~/lib/jquery/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="~/lib/ligerUI/js/ligerui.all.js"></script>
    <script src="~/Scripts/common.js?v=@DateTime.Now.ToString("yyyyMMdd")"></script>
    <script src="~/Scripts/jquery-easyui/jquery.easyui.min.js"></script>
    <link href="~/Scripts/jquery-easyui/themes/metro/easyui.css" rel="stylesheet" type="text/css">
    <style type="text/css">
        .gridtable { width: 380px; margin: 0px; }
        .gridtable td { height: 30px; line-height: 30px; }
    </style>
</head>
<body>
    <form>
        <div style="margin:10px 0px;">
            <table class="gridtable">
                <tr>
                    <td style="text-align:right; width:100px;">
                        班别类型：
                    </td>
                    <td>
                        <input type="text" id="txtScheduleType" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right; width:100px;">
                        班别名称：
                    </td>
                    <td>
                        <input type="text" id="txtName" name="txtName" class="l-text" style="width:200px;" value="@schedulingCategory.Name" @(ViewBag.IsEdit ? "" : "readonly='readonly'")/>
                        <span style="color:#ff0000">*</span>
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right; width:100px;">
                        显示符号：
                    </td>
                    <td>
                        <input type="text" id="txtCode" name="txtCode" class="l-text" style="width:200px;" value="@schedulingCategory.Code" @(ViewBag.IsEdit ? "" : "readonly='readonly'") />
                        <span style="color:#ff0000">*</span>
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right; width:100px;">
                        字体颜色：
                    </td>
                    <td>
                        <input type="text" id="txtColor" value="@schedulingCategory.Color" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right; width:100px;">
                        班别排序：
                    </td>
                    <td>
                        <input type="text" id="txtiSort" name="txtiSort" class="l-text" style="width:200px;" typeof="number" maxlength="5" value="@schedulingCategory.Sort" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right; width:100px;">
                        班别系数：
                    </td>
                    <td>
                        <input type="text" id="txtRatio" name="txtRatio" class="l-text" style="width:200px;" value="@schedulingCategory.Ratio" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right; width:100px;">
                        上班时间：
                    </td>
                    <td>
                        <input type="text" id="txtStartWorkTime" name="txtStartWorkTime" class="easyui-timespinner" style="width: 202px; height: 22px;" value="@schedulingCategory.StatrWorkTime" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right; width:100px;">
                        下班时间 ：
                    </td>
                    <td>
                        <input type="text" id="txtEndWorkTime" name="txtEndWorkTime" class="easyui-timespinner" style="width: 202px; height: 22px;" value="@schedulingCategory.EndWorkTime" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right; width:100px;">
                        工时(小时)：
                    </td>
                    <td>
                        <input type="text" id="txtWorkHours" name="txtWorkHours" class="l-text" style="width:200px;" maxlength="5" value="@schedulingCategory.WorkHours" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right; width:100px;">
                        所属病区：
                    </td>
                    <td>
                        <input type="text" id="txtillArea" />
                    </td>
                </tr>
                <tr>
                    <td style="text-align:right; width:100px;">
                        启用：
                    </td>
                    <td>
                        <input type="checkbox" id="cbxEnabled" class="l-checkbox" @(schedulingCategory.Enabled == 1 ? "checked='checked'" : "") />
                        <input type="hidden" id="hdnEnabled" name="hdnEnabled" value="@(schedulingCategory.Enabled == 1 ? 1 : 0)" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align:center;padding-top:10px;">
                        <input id="btnSubmit" type="button" value="确定" class="l-button" />&nbsp;&nbsp;&nbsp;
                        <input id="btnClose" type="button" value="取消" class="l-button-cancel" />
                        <input type="hidden" id="hdnId" name="hdnId" value="@schedulingCategory.Id" />
                    </td>
                </tr>
            </table>
        </div>
    </form>
    <script type="text/javascript">
        var dataformInit;
        var jsonTextInit;
        function save() {
            //var dataform = $("form").serializeArray();
            //var jsonText = JSON.stringify({ dataform: dataform });
            //if (jsonTextInit == jsonText && parseInt($("#hdnId").val()) > 0) {
            //    var manager1 = $.ligerDialog.waitting('保存成功...');
            //    setTimeout(function () {
            //        manager1.close();
            //        frameElement.dialog.close();
            //    }, 1000);
            //    return false;
            //}
            if (IsEmpty($("#txtiSort").val())) $("#txtiSort").val(1);
            if (IsEmpty($("#txtName").val())) { $.ligerDialog.error("请输入班别名称"); return; }
            if (IsEmpty($("#txtCode").val())) { $.ligerDialog.error("请输入显示符号"); return; }

            var st = $("#txtScheduleType").ligerComboBox().getValue();
            var ia = $("#txtillArea").ligerComboBox().getValue();
            if (st == 2 && (ia == 0 || IsEmpty(ia))) {
                $.ligerDialog.error("如果班别类型是自定义，请选择一个所属病区"); return;
            }

            
            var arr = $("form").serializeArray();
            var obj = {};
            for (var i = 0; i < arr.length; i++) {
                obj[arr[i].name] = arr[i]['value']
            }
            $.post("/SchedulingType/Save", obj, function (data, textStatus) {
                if (textStatus == "success") {
                    var d = $.parseJSON(data);
                    if (d.Result == 1) {
                        parent.window.btnSearch.click();
                        $.ligerDialog.success("保存成功");
                        frameElement.dialog.close();
                    }
                    else if (d.Result == 0) {
                        $.ligerDialog.error(d.Body);
                    }
                    else {
                        $.ligerDialog.error("程序错误");
                    }
                } else { $.ligerDialog.error("程序错误"); }
            });
        }
        var combobox;
        $(document).ready(function () {
            $("#btnClose").click(function () {
                frameElement.dialog.close();
            })
            $("#cbxEnabled").click(function () {
                $("#hdnEnabled").val(($('#cbxEnabled').prop('checked')) ? 1 : 0);
            });
            $("#btnSubmit").click(function () {
                save();
            });

            //病区
            combobox = $("#txtillArea").ligerComboBox({
                width: 200,
                //data: [{ "value": 0, "text": "全部" }],
                url: '/Scheduling/SchedulingType/GetDepartmentList?ram=' + Math.random(),
                isMultiSelect: false,
                valueField: "value",
                textField: "text",
                value: '0',
                valueFieldID: 'hdnillArea',
                onSuccess: function (data) {
                    combobox.insertItem({ "value": "0", "text": "-请选择-" }, 0);
                    $("#txtillArea").ligerGetComboBoxManager().setValue("@LoginManager.GetLoginUser().CurrDepCode");
                    if ("@schedulingCategory.DepartmentCode" != "") {
                        $("#txtillArea").ligerGetComboBoxManager().setValue("@schedulingCategory.DepartmentCode");
                    }
                    $("#txtName").focus();
                    dataformInit = $("form").serializeArray();
                    jsonTextInit = JSON.stringify({ dataform: dataformInit });
                }
            });

            var flag = false;
            //班别类型
            $("#txtScheduleType").ligerComboBox({
                width: 200,
                data: [{ "ID": 1, "Name": "全院通用" }, { "ID": 2, "Name": "自定义" }],
                //url: "",
                isMultiSelect: false,
                valueField: "ID",
                textField: "Name",
                value: '0',
                valueFieldID: 'hdnScheduleType',
                onSuccess: function (data) { },
                onSelected: function (Id, Name) {
                    if (flag) {
                        if (Id == "1") {
                            $("#txtillArea").ligerGetComboBoxManager().setDisabled();
                        } else {
                            $("#txtillArea").ligerGetComboBoxManager().setEnabled();
                            if (typeof ($("#txtillArea").ligerGetComboBoxManager().data[1]) != "undefined")
                                $("#txtillArea").ligerGetComboBoxManager().setValue($("#txtillArea").ligerGetComboBoxManager().data[1].value);
                        }
                    }

                }
            });
            $("#txtScheduleType").ligerGetComboBoxManager().setValue("2");
            flag = true;
            if ("@schedulingCategory.CategoryType" != "")
                $("#txtScheduleType").ligerGetComboBoxManager().setValue("@schedulingCategory.CategoryType");


            //颜色
            $("#txtColor").ligerComboBox({
                width: 200,
                data: [{ "ID": "Black", "Name": "黑色" }, { "ID": "Red", "Name": "红色" }, { "ID": "Gray", "Name": "灰色" }, { "ID": "Green", "Name": "绿色" }, { "ID": "Blue", "Name": "蓝色" }],
                //url: "",
                isMultiSelect: false,
                valueField: "ID",
                textField: "Name",
                value: '0',
                valueFieldID: 'hdnColor',
                onSuccess: function (data) { }
            });
            $("#txtColor").ligerGetComboBoxManager().setValue("Black");
            if ("@schedulingCategory.Color" != "")
                $("#txtColor").ligerGetComboBoxManager().setValue("@schedulingCategory.Color");

            //if ($("#txtName").is(":disabled"))
            //    $("#txtColor").ligerGetComboBoxManager().setDisabled();

            //数字输入
            $(":text[typeof=number]").keyup(function () {
                var c = $(this);
                if (/[^\d]/.test(c.val())) {
                    var num = c.val().replace(/[^\d]/g, '');
                    $(this).val(num == "" ? "" : parseInt(num));
                }
            });
        });
    </script>
</body>
</html>